

# P67  "Don't panic!" => list => "on tap"
phrase = "Don't panic!"
plist = list(phrase)  # str 转换 list 使用的方法是 list(str)
print(phrase)
print(plist)

for i in range(4):
    # 循环执行4次 删除末位 使用方法 pop()
    plist.pop()
print(plist)
plist.pop(0)
print(plist)
plist.remove("'")
print(plist)
# extend ==> plist + ["a","p"]
plist.extend([plist.pop(),plist.pop()]) # 运算顺序，（1*（5+1））
#['o','n','t',' ']   a           p
print(plist)

plist.insert(2,plist.pop(3))
#                   ' '
print(plist)
new_phrase = ''.join(plist) #? ''.join() list 转换 str
print("plist=",plist) # list的方法会打乱和改变list的内容
print("new_phrase=",new_phrase)

# p82 panic2
phrase = "Don't panic!"
plist = list(phrase)
print(phrase)
print(plist)
print(plist)
print(new_phrase)
new_phrase = ''.join(plist[1:3])   # started by slicing out the word “on” from “plist”.
new_phrase = new_phrase + ''.join([plist[5], plist[4], plist[7], plist[6]])  #then picked out each additional letter that we needed: space, “t”, “a”, and “p

#  for loop
paranoid_android = "Marvin"
letters = list(paranoid_android)
for char in letters :
    print('\t',char)

# slices
paranoid_android = "Marvin, the Paranoid Android"
letters = list(paranoid_android)
for char in letters[:6]:
    print('\t', char)
print()
for char in letters[-7:]:
    print('\t'*2,char)  #  multiplication operator (*)
print()
for char in letters[12:20]:
     print('\t'*3,char)
